package com.example.observe.gperadvice;

import java.util.Observable;

/**
 * 咕泡社区，被观察者，采用 jdk 自带的模式需要继承 Observable 接口才能被观察
 */
public class GPer extends Observable {


    private String name = "GPer社区";
    private static GPer gper;

    private GPer() {
    }

    public String getName() {
        return name;
    }


    public static GPer getInstance() {
        if (gper == null) {
            gper = new GPer();
        }
        return gper;
    }


    public void publishQuestion(Question question) {

        System.out.println(question.getUsername() + "在" + name + "发布了一个问题：" + question.getContent());

        setChanged();
        // 通知观察者，同时把问题传过去
        notifyObservers(question);


    }

}
